<template>
  <!-- 组件属性 -->
  <div
    class="Fg-field"
    v-if="activeData && Object.keys(activeData).length"
    :key="activeData.__config__.formId"
  >
    <!-- <el-form
      size="small"
      label-position="left"
      label-width="90px"
      style="margin-top:-16px;padding:5px 0"
    >
      <el-form-item v-if="activeData.isLock !== undefined" label="是否锁定">
        <el-switch :value="activeData.isLock" @change="handleLock(activeData)" />
      </el-form-item>
    </el-form>-->
    <el-form size="small" label-position="left" label-width="90px" :disabled="activeData.isLock">
      <div class="Fg-field-name">属性配置</div>
      <el-form-item v-if="activeData.__config__.changeTag" label="组件类型">
        <el-select
          :value="activeData.__config__.tagIcon"
          placeholder="请选择组件类型"
          :style="{ width: '100%' }"
          @change="tagChange"
        >
          <el-option-group v-for="group in tagList" :key="group.label" :label="group.label">
            <el-option
              v-for="item in group.options"
              :key="item.__config__.label"
              :label="item.__config__.label"
              :value="item.__config__.tagIcon"
            >
              <svg-icon class="node-icon" :icon-class="item.__config__.tagIcon" />
              <span>{{ item.__config__.label }}</span>
            </el-option>
          </el-option-group>
        </el-select>
      </el-form-item>
      <el-form-item v-if="activeData.__vModel__ !== undefined" label="字段名">
        <el-input readonly v-model="activeData.__vModel__" placeholder="请输入字段名（v-model）" />
      </el-form-item>
      <el-form-item v-if="activeData.__config__.componentName !== undefined" label="组件名">
        {{ activeData.__config__.componentName }}
        <!-- <el-input v-model="activeData.__config__.componentName" placeholder="请输入组件名" maxlength="50" /> -->
      </el-form-item>
      <el-form-item required v-if="activeData.__config__.label !== undefined" label="标题">
        <el-input
          v-model="activeData.__config__.label"
          placeholder="请输入标题"
          @input="changeRenderKey"
        />
      </el-form-item>
      <el-form-item v-if="activeData.header !== undefined" label="标题">
        <el-input v-model="activeData.header" placeholder="请输入标题" @input="changeRenderKey" />
      </el-form-item>
      <el-form-item v-if="activeData.placeholder !== undefined" label="占位提示">
        <el-input
          v-model="activeData.placeholder"
          placeholder="请输入占位提示"
          @input="changeRenderKey"
          maxlength="50"
        />
      </el-form-item>
      <el-form-item v-if="activeData['start-placeholder'] !== undefined" label="开始占位">
        <el-input v-model="activeData['start-placeholder']" placeholder="请输入占位提示" maxlength="50" />
      </el-form-item>
      <el-form-item v-if="activeData['end-placeholder'] !== undefined" label="结束占位">
        <el-input v-model="activeData['end-placeholder']" placeholder="请输入占位提示" maxlength="50" />
      </el-form-item>
      <el-form-item v-if="activeData.__config__.span !== undefined" label="表单栅格">
        <el-slider v-model="activeData.__config__.span" :max="24" :min="1" :marks="{ 12: '' }" />
      </el-form-item>
      <el-form-item
        v-if="
        activeData.__config__.tagType == 'layout' &&
        activeData.gutter !== undefined
      "
        label="栅格间隔"
      >
        <el-input-number v-model="activeData.gutter" :min="0" placeholder="栅格间隔" />
      </el-form-item>
      <template v-if="activeData.__config__.isStage">
        <!-- <el-divider /> -->
        <el-form-item v-if="activeData.__config__.defaultValue !==undefined" label="默认选中">
          <el-input
            :value="setDefaultValue(activeData.__config__.defaultValue)"
            placeholder="请输入默认值"
            :maxlength="50"
            @input="onDefaultValueInput"
          />
        </el-form-item>
        <el-form-item
          v-if="
        activeData.__config__.tag === 'form-tabs-container' &&
        activeData.type !== undefined
      "
          label="风格类型"
        >
          <el-radio-group v-model="activeData.type">
            <el-radio-button label>默认</el-radio-button>
            <el-radio-button label="card">标签</el-radio-button>
            <el-radio-button label="border-card">卡片</el-radio-button>
          </el-radio-group>
        </el-form-item>
        
        <el-form-item v-if="activeData.direction !==undefined" label="显示方向">
          <el-radio-group v-model="activeData.direction">
            <el-radio-button label="horizontal">水平排列</el-radio-button>
            <el-radio-button label="vertical">垂直排列</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="activeData.simple !==undefined" label="显示简洁风格">
          <el-switch v-model="activeData.simple" />
        </el-form-item>
        <HuOptions
          v-if="activeData.children!==undefined"
          :options.sync="activeData.children"
          title="子节点列表"
        />
      </template>

      <el-form-item
        v-if="
        activeData.__config__.tag === 'form-row-container' &&
        activeData.type !== undefined
      "
        label="布局模式"
      >
        <el-radio-group v-model="activeData.type">
          <el-radio-button label="default" />
          <el-radio-button label="flex" />
        </el-radio-group>
      </el-form-item>
      <el-form-item
        v-if="activeData.justify !== undefined && activeData.type === 'flex'"
        label="水平排列"
      >
        <el-select v-model="activeData.justify" placeholder="请选择水平排列" :style="{ width: '100%' }">
          <el-option
            v-for="(item, index) in justifyOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item
        v-if="activeData.align !== undefined && activeData.type === 'flex'"
        label="垂直排列"
      >
        <el-radio-group v-model="activeData.align">
          <el-radio-button label="top" />
          <el-radio-button label="middle" />
          <el-radio-button label="bottom" />
        </el-radio-group>
      </el-form-item>
      <el-form-item label="栅格间隔" v-if="activeData.gutter !== undefined">
        <el-input-number v-model="activeData.gutter" :min="0" placeholder="栅格间隔" />
      </el-form-item>
      <el-form-item v-if="activeData.__config__.labelWidth !== undefined" label="标签宽度">
        <el-input
          v-model.number="activeData.__config__.labelWidth"
          type="number"
          placeholder="请输入标签宽度"
        />
      </el-form-item>

      <el-form-item
        v-if="
        activeData.__vModel__ !== undefined &&
        !activeData.__config__.defaultValueHidden && activeData.__config__.defaultValue!== undefined
      "
        label="默认值"
      >
        <el-input
          :value="setDefaultValue(activeData.__config__.defaultValue)"
          placeholder="请输入默认值"
          :maxlength="activeData.maxlength || 200"
          @input="onDefaultValueInput"
        />
      </el-form-item>
      <el-form-item v-if="activeData.html !==undefined" label="HTML内容">
        <el-button
          type="primary"
          plain
          size="small"
          @click="$refs.HTMLEditor.open(activeData.html)"
        >编辑数据</el-button>
        <CodeDialog ref="HTMLEditor" v-model="activeData.html" mode="text/html" />
      </el-form-item>

      <el-form-item v-if="activeData.__config__.tag === 'form-checkbox-group'" label="至少应选">
        <el-input-number
          :value="activeData.min"
          :min="0"
          placeholder="至少应选"
          @input="$set(activeData, 'min', $event ? $event : undefined)"
        />
      </el-form-item>
      <el-form-item v-if="activeData.__config__.tag === 'form-checkbox-group'" label="最多可选">
        <el-input-number
          :value="activeData.max"
          :min="0"
          placeholder="最多可选"
          @input="$set(activeData, 'max', $event ? $event : undefined)"
        />
      </el-form-item>
      <el-form-item
        v-if="activeData.__slot__ && activeData.__slot__.prepend !== undefined"
        label="前缀"
      >
        <el-input v-model="activeData.__slot__.prepend" placeholder="请输入前缀" />
      </el-form-item>
      <el-form-item
        v-if="activeData.__slot__ && activeData.__slot__.append !== undefined"
        label="后缀"
      >
        <el-input v-model="activeData.__slot__.append" placeholder="请输入后缀" />
      </el-form-item>
      <el-form-item v-if="activeData['prefix-icon'] !== undefined" label="前图标">
        <el-input v-model="activeData['prefix-icon']" placeholder="请输入前图标名称" clearable>
          <el-button slot="append" icon="el-icon-thumb" @click="openIconsDialog('prefix-icon')">选择</el-button>
        </el-input>
      </el-form-item>
      <el-form-item v-if="activeData['suffix-icon'] !== undefined" label="后图标">
        <el-input v-model="activeData['suffix-icon']" placeholder="请输入后图标名称" clearable>
          <el-button slot="append" icon="el-icon-thumb" @click="openIconsDialog('suffix-icon')">选择</el-button>
        </el-input>
      </el-form-item>
      <el-form-item v-if="activeData.__config__.tag === 'form-cascader'" label="选项分隔符">
        <el-input v-model="activeData.separator" placeholder="请输入选项分隔符" />
      </el-form-item>
      <el-form-item v-if="activeData.autosize !== undefined" label="最小行数">
        <el-input-number v-model="activeData.autosize.minRows" :min="1" placeholder="最小行数" />
      </el-form-item>
      <el-form-item v-if="activeData.autosize !== undefined" label="最大行数">
        <el-input-number v-model="activeData.autosize.maxRows" :min="1" placeholder="最大行数" />
      </el-form-item>
      <el-form-item v-if="isShowMin" label="最小值">
        <el-input-number v-model="activeData.min" placeholder="最小值" />
      </el-form-item>
      <el-form-item v-if="isShowMax" label="最大值">
        <el-input-number v-model="activeData.max" placeholder="最大值" />
      </el-form-item>
      <el-form-item v-if="activeData.height !== undefined" label="组件高度">
        <el-input-number v-model="activeData.height" placeholder="高度" @input="changeRenderKey" />
      </el-form-item>
      <el-form-item v-if="activeData.width !== undefined" label="组件宽度">
        <el-input-number v-model="activeData.width" placeholder="宽度" @input="changeRenderKey" />
      </el-form-item>
      <el-form-item v-if="isShowStep" label="步长">
        <el-input-number v-model="activeData.step" placeholder="步数" />
      </el-form-item>
      <el-form-item v-if="activeData.__config__.tag === 'form-input-number'" label="精度">
        <el-input-number v-model="activeData.precision" :min="0" placeholder="精度" />
      </el-form-item>
      <el-form-item v-if="activeData.__config__.tag === 'form-input-number'" label="按钮位置">
        <el-radio-group v-model="activeData['controls-position']">
          <el-radio-button label>默认</el-radio-button>
          <el-radio-button label="right">右侧</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="activeData.maxlength !== undefined" label="最多输入">
        <el-input v-model="activeData.maxlength" placeholder="请输入字符长度">
          <template slot="append">个字符</template>
        </el-input>
      </el-form-item>
      <el-form-item v-if="activeData['active-text'] !== undefined" label="开启提示">
        <el-input v-model="activeData['active-text']" placeholder="请输入开启提示" />
      </el-form-item>
      <el-form-item v-if="activeData['inactive-text'] !== undefined" label="关闭提示">
        <el-input v-model="activeData['inactive-text']" placeholder="请输入关闭提示" />
      </el-form-item>
      <el-form-item v-if="activeData['active-value'] !== undefined" label="开启值">
        <el-input
          :value="setDefaultValue(activeData['active-value'])"
          placeholder="请输入开启值"
          @input="onSwitchValueInput($event, 'active-value')"
        />
      </el-form-item>
      <el-form-item v-if="activeData['inactive-value'] !== undefined" label="关闭值">
        <el-input
          :value="setDefaultValue(activeData['inactive-value'])"
          placeholder="请输入关闭值"
          @input="onSwitchValueInput($event, 'inactive-value')"
        />
      </el-form-item>
      <el-form-item
        v-if="
        activeData.type !== undefined &&
        'form-date-picker' === activeData.__config__.tag
      "
        label="时间类型"
      >
        <el-select
          v-model="activeData.type"
          placeholder="请选择时间类型"
          :style="{ width: '100%' }"
          @change="dateTypeChange"
        >
          <el-option
            v-for="(item, index) in dateOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item v-if="activeData.accept !== undefined" label="文件类型">
        <el-select
          v-model="activeData.accept"
          placeholder="请选择文件类型"
          :style="{ width: '100%' }"
          clearable
        >
          <el-option
            v-for="item in fileTypeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-if="activeData.__config__.fileSize !== undefined" label="文件大小">
        <el-input v-model.number="activeData.__config__.fileSize" placeholder="请输入文件大小">
          <el-select
            slot="append"
            v-model="activeData.__config__.sizeUnit"
            :style="{ width: '66px' }"
          >
            <el-option label="KB" value="KB" />
            <el-option label="MB" value="MB" />
            <el-option label="GB" value="GB" />
          </el-select>
        </el-input>
      </el-form-item>
      <el-form-item v-if="activeData.limit !== undefined" label="最大允许上传个数">
        <el-input-number v-model="activeData.limit" />
      </el-form-item>
      <el-form-item v-if="activeData.action !== undefined" label="上传地址">
        <el-input v-model="activeData.action" placeholder="请输入上传地址" clearable />
      </el-form-item>
      <el-form-item v-if="activeData.name !== undefined" label="上传字段名">
        <el-input v-model="activeData.name" placeholder="请输入上传文件字段名" />
      </el-form-item>
      <el-form-item v-if="activeData.download !== undefined" label="下载地址">
        <el-input v-model="activeData.download" placeholder="请输入下载地址" clearable />
      </el-form-item>
      <el-form-item v-if="activeData.dName !== undefined" label="下载字段名">
        <el-input v-model="activeData.dName" placeholder="请输入下载文件字段名" />
      </el-form-item>
      <el-form-item v-if="activeData.href !== undefined" label="跳转链接">
        <el-input v-model="activeData.href" placeholder="请输入跳转链接" maxlength="200" />
      </el-form-item>
      <el-form-item
        v-if="
        activeData.type !== undefined &&
        (activeData.__config__.tag === 'form-link' || activeData.__config__.tag === 'form-tag')
      "
        label="类型"
      >
        <el-select v-model="activeData.type" :style="{ width: '100%' }">
          <el-option label="primary" value="primary" />
          <el-option label="success" value="success" />
          <el-option label="warning" value="warning" />
          <el-option label="danger" value="danger" />
          <el-option label="info" value="info" />
          <el-option
            v-if="activeData.__config__.tag === 'form-link'"
            label="default"
            value="default"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-if="activeData.underline !== undefined" label="显示下划线">
        <el-switch v-model="activeData.underline" />
      </el-form-item>
      <el-form-item v-if="activeData.__config__.buttonText !== undefined" label="按钮文字">
        <el-input v-model="activeData.__config__.buttonText" placeholder="请输入按钮文字" />
      </el-form-item>
      <el-form-item v-if="activeData['range-separator'] !== undefined" label="分隔符">
        <el-input v-model="activeData['range-separator']" placeholder="请输入分隔符" />
      </el-form-item>
      <el-form-item v-if="activeData['picker-options'] !== undefined" label="时间段">
        <el-input v-model="activeData['picker-options'].selectableRange" placeholder="请输入时间段" />
      </el-form-item>
      <el-form-item v-if="activeData.format !== undefined" label="时间格式">
        <el-input :value="activeData.format" placeholder="请输入时间格式" @input="setTimeValue($event)" />
      </el-form-item>
      <el-form-item v-if="activeData.description !== undefined" label="辅助文字">
        <el-input v-model="activeData.description" placeholder="请输入辅助文字" maxlength="500" />
      </el-form-item>
      <HuOptions
        v-if="activeData.__slot__ && activeData.__slot__.options!==undefined"
        :options.sync="activeData.__slot__.options"
      />
      <!-- 图标 -->
      <el-form-item v-if="activeData['icon'] !== undefined" label="图标">
        <el-input v-model="activeData['icon']" placeholder="请输入后图标名称" clearable>
          <el-button slot="append" icon="el-icon-thumb" @click="openIconsDialog('icon')">选择</el-button>
        </el-input>
      </el-form-item>
      <!-- 画笔粗细 -->
      <el-form-item v-if="activeData['lineWidth'] !== undefined" label="画笔粗细">
        <el-input-number v-model="activeData.lineWidth" :min="1" :max="10" />
      </el-form-item>

      <!-- 选中颜色 -->
      <el-form-item
        v-if="activeData['color'] !== undefined"
        :label="{'form-rate':'选中','':''}[activeData.__config__.tag] || ''+'颜色'"
      >
        <InputColor v-model="activeData['color']" />
      </el-form-item>
      <el-form-item v-if="activeData['textColor'] !== undefined" label="文本颜色">
        <InputColor v-model="activeData['textColor']" />
      </el-form-item>
      <!-- 未选中颜色 -->
      <el-form-item v-if="activeData['voidColor'] !== undefined" label="未选中颜色">
        <InputColor v-model="activeData['voidColor']" />
      </el-form-item>
      <!-- 背景颜色 -->
      <el-form-item v-if="activeData['bgColor'] !== undefined" label="背景颜色">
        <InputColor v-model="activeData['bgColor']" />
      </el-form-item>
      <!-- 画笔颜色 -->
      <el-form-item v-if="activeData['lineColor'] !== undefined" label="画笔颜色">
        <InputColor v-model="activeData['lineColor']" />
      </el-form-item>

      <!-- 轮播图 -->
      <template v-if="activeData.__config__.tag=='form-swipe'">
        <el-form-item v-if="activeData.type !== undefined">
          <span slot="label">
            类型
            <el-tooltip content="卡片类型仅在pc端生效" placement="top">
              <i class="el-icon-question"></i>
            </el-tooltip>
          </span>
          <el-radio-group v-model="activeData.type">
            <el-radio-button label="default">默认</el-radio-button>
            <el-radio-button label="card">卡片化</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="activeData.initialIndex !== undefined" label="初始位置索引">
          <el-input-number v-model="activeData.initialIndex" :min="0" />
        </el-form-item>
        <el-form-item v-if="activeData.autoplay !== undefined" label="是否自动切换">
          <el-switch v-model="activeData.autoplay" />
        </el-form-item>
        <el-form-item v-if="activeData.loop !== undefined" label="是否循环显示">
          <el-switch v-model="activeData.loop" />
        </el-form-item>
        <el-form-item v-if="activeData.direction !==undefined" label="展示方向">
          <el-radio-group v-model="activeData.direction">
            <el-radio-button label="horizontal">水平排列</el-radio-button>
            <el-radio-button label="vertical">垂直排列</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="activeData.interval !==undefined" label="自动切换时间">
          <!-- <el-input-number v-model="activeData.interval" :min="0" /> -->
          <el-input type="number" placeholder="请输入切换时间" v-model.number="activeData.interval">
            <template slot="append">ms</template>
          </el-input>
        </el-form-item>
      </template>
      <el-form-item v-if="activeData.speed !== undefined" label="滚动速率">
        <el-input type="number" v-model.number="activeData.speed">
          <template slot="append">px/s</template>
        </el-input>
      </el-form-item>
      <el-form-item v-if="activeData.center !== undefined" label="是否居中">
        <el-switch v-model="activeData.center" />
      </el-form-item>

      <el-form-item v-if="activeData.__config__.optionType !== undefined" label="选项样式">
        <el-radio-group v-model="activeData.__config__.optionType">
          <el-radio-button label="default">默认</el-radio-button>
          <el-radio-button label="button">按钮</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="activeData['active-color'] !== undefined" label="开启颜色">
        <InputColor v-model="activeData['active-color']" />
      </el-form-item>
      <el-form-item v-if="activeData['inactive-color'] !== undefined" label="关闭颜色">
        <InputColor v-model="activeData['inactive-color']" />
      </el-form-item>

      <el-form-item
        v-if="
        activeData.__config__.showLabel !== undefined &&
        activeData.__config__.labelWidth !== undefined
      "
        label="显示标签"
      >
        <el-switch v-model="activeData.__config__.showLabel" />
      </el-form-item>

      <el-form-item v-if="activeData['allow-half'] !== undefined" label="允许半选">
        <el-switch v-model="activeData['allow-half']" />
      </el-form-item>
      <el-form-item v-if="activeData['show-text'] !== undefined" label="辅助文字">
        <el-switch v-model="activeData['show-text']" @change="rateTextChange" />
      </el-form-item>
      <el-form-item v-if="activeData['show-score'] !== undefined" label="显示分数">
        <el-switch v-model="activeData['show-score']" @change="rateScoreChange" />
      </el-form-item>
      <el-form-item v-if="activeData['show-stops'] !== undefined" label="显示间断点">
        <el-switch v-model="activeData['show-stops']" />
      </el-form-item>
      <el-form-item v-if="activeData.range !== undefined" label="范围选择">
        <el-switch v-model="activeData.range" @change="rangeChange" />
      </el-form-item>
      <el-form-item
        v-if="
        activeData.__config__.border !== undefined &&
        activeData.__config__.optionType === 'default'
      "
        label="是否带边框"
      >
        <el-switch v-model="activeData.__config__.border" />
      </el-form-item>
      <el-form-item v-if="activeData.__config__.tag === 'form-color-picker'" label="颜色格式">
        <el-select
          v-model="activeData['color-format']"
          placeholder="请选择颜色格式"
          :style="{ width: '100%' }"
          clearable
          @change="colorFormatChange"
        >
          <el-option
            v-for="(item, index) in colorFormatOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item
        v-if="
        activeData.size !== undefined &&
        (activeData.__config__.optionType === 'button' ||
          activeData.__config__.border ||
          activeData.__config__.tag === 'form-color-picker' ||
          activeData.__config__.tag === 'form-button' ||
          activeData.__config__.tag === 'form-table'||
          activeData.__config__.tag === 'form-tag')
      "
        label="组件尺寸"
      >
        <el-radio-group v-model="activeData.size">
          <el-radio-button label="medium">中等</el-radio-button>
          <el-radio-button label="small">较小</el-radio-button>
          <el-radio-button label="mini">迷你</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="activeData.hit !== undefined" label="显示边框描边">
        <el-switch v-model="activeData.hit"></el-switch>
      </el-form-item>
      <el-form-item v-if="activeData.closable !== undefined" label="可关闭">
        <el-switch v-model="activeData.closable"></el-switch>
      </el-form-item>
      <el-form-item v-if="activeData.plain !== undefined" label="是否朴素按钮">
        <el-switch v-model="activeData.plain"></el-switch>
      </el-form-item>
      <el-form-item v-if="activeData.round !== undefined" label="是否为圆角">
        <el-switch v-model="activeData.round"></el-switch>
      </el-form-item>
      <el-form-item v-if="activeData.circle !== undefined" label="是否为圆形">
        <el-switch v-model="activeData.circle"></el-switch>
      </el-form-item>
      <el-form-item v-if="activeData.effect !== undefined" label="主题">
        <el-select v-model="activeData.effect" :style="{ width: '100%' }">
          <el-option label="dark" value="dark" />
          <el-option label="light" value="light" />
          <el-option label="plain" value="plain" />
        </el-select>
      </el-form-item>
      <el-form-item v-if="activeData.target !== undefined" label="打开方式">
        <el-select v-model="activeData.target" :style="{ width: '100%' }">
          <el-option label="当前窗口" value="_self" />
          <el-option label="新的窗口" value="_blank" />
          <el-option label="父级窗口" value="_parent" />
          <el-option label="顶级窗口" value="_top" />
        </el-select>
      </el-form-item>
      <el-form-item v-if="activeData['show-word-limit'] !== undefined" label="输入统计">
        <el-switch v-model="activeData['show-word-limit']" />
      </el-form-item>
      <el-form-item v-if="activeData.__config__.tag === 'form-input-number'" label="严格步数">
        <el-switch v-model="activeData['step-strictly']" />
      </el-form-item>

      <el-form-item v-if="activeData.__config__.tag === 'form-cascader'" label="展示全路径">
        <el-switch v-model="activeData['show-all-levels']" />
      </el-form-item>
      <el-form-item v-if="activeData.__config__.tag === 'form-cascader'" label="可否筛选">
        <el-switch v-model="activeData.filterable" />
      </el-form-item>
      <el-form-item v-if="activeData.clearable !== undefined" label="能否清空">
        <el-switch v-model="activeData.clearable" />
      </el-form-item>
      <el-form-item v-if="activeData.__config__.showTip !== undefined" label="显示提示">
        <el-switch v-model="activeData.__config__.showTip" />
      </el-form-item>

      <el-form-item v-if="activeData.__config__.tag === 'form-select'" label="能否搜索">
        <el-switch v-model="activeData.filterable" />
      </el-form-item>
      <el-form-item v-if="activeData.transcoding !== undefined" label="是否开启转码">
        <el-switch v-model="activeData.transcoding" />
      </el-form-item>

      <el-form-item v-if="activeData.multiple !== undefined" label="是否多选">
        <el-switch v-model="activeData.multiple" />
      </el-form-item>
      <!-- <el-form-item v-if="activeData.enablePrint !== undefined" label="可打印">
      <el-switch v-model="activeData.enablePrint" />
      </el-form-item>-->
      <el-form-item v-if="activeData.readonly !== undefined" label="是否只读">
        <el-switch v-model="activeData.readonly" />
      </el-form-item>
      <el-form-item v-if="activeData.disabled !== undefined" label="是否禁用">
        <el-switch v-model="activeData.disabled" />
      </el-form-item>
      <el-form-item v-if="activeData.isHide !== undefined" label="是否隐藏">
        <el-switch v-model="activeData.isHide" />
      </el-form-item>
      <el-form label-width="90px" size="small">
        <el-form-item v-if="activeData.isLock !== undefined" label="是否锁定">
          <el-switch :value="activeData.isLock" @change="handleLock(activeData)" />
        </el-form-item>
      </el-form>

      <el-form-item v-if="activeData.contentPosition !== undefined" label="文案位置">
        <el-select v-model="activeData.contentPosition" :style="{ width: '100%' }">
          <el-option label="left" value="left" />
          <el-option label="center" value="center" />
          <el-option label="right" value="right" />
        </el-select>
      </el-form-item>

      <el-form-item v-if="activeData.maxSize !== undefined">
        <span slot="label">
          最大行数
          <el-tooltip content="允许添加多少条记录" placement="top">
            <i class="el-icon-question"></i>
          </el-tooltip>
        </span>
        <el-input-number v-model="activeData.maxSize" :min="1" />
      </el-form-item>
      <el-form-item v-if="activeData.subType !== undefined" label="布局方式">
        <span slot="label">
          布局方式
          <el-tooltip content="因尺寸原因，移动端只显示“按表单”布局" placement="top">
            <i class="el-icon-question"></i>
          </el-tooltip>
        </span>
        <el-radio-group v-model="activeData.subType">
          <el-radio-button label="table">按表格</el-radio-button>
          <el-radio-button label="form">按表单</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="activeData.shadow !== undefined" label="阴影显示时机">
        <el-select v-model="activeData.shadow" :style="{ width: '100%' }">
          <el-option label="常显" value="always" />
          <el-option label="不显示" value="never" />
          <el-option label="悬浮" value="hover" />
        </el-select>
      </el-form-item>

      <!-- 表格属性 -->
      <template v-if="activeData.subType =='table'||activeData.__config__.tag=='form-table' ">
        <el-form-item v-if="activeData.stripe !== undefined" label="是否为斑马纹">
          <el-switch v-model="activeData.stripe" />
        </el-form-item>
        <el-form-item v-if="activeData.border !== undefined" label="是否带有纵向边框">
          <el-switch v-model="activeData.border" />
        </el-form-item>
        <el-form-item v-if="activeData.showHeader !== undefined" label="是否显示表头">
          <el-switch v-model="activeData.showHeader" />
        </el-form-item>
      </template>
      <TableConfig v-model="activeData" />
      <template v-if="activeData.__config__.layoutTree">
        <!-- 布局结构树 -->
        <LayoutTree :value="activeData" />
      </template>
      <!-- 数据配置 -->
      <template v-if="activeData.dataObj">
        <div class="Fg-field-name">数据配置</div>
        <DataConfig v-if="activeData.dataObj" v-model="activeData.dataObj" />
      </template>
      <!-- 验证配置 -->
      <template v-if="activeData.__config__.regList">
        <div class="Fg-field-name">验证配置</div>
        <el-form-item v-if="activeData.__config__.required !== undefined" label="是否必填">
          <el-switch v-model="activeData.__config__.required" />
        </el-form-item>
        <RegConfig v-model="activeData.__config__.regList" />
      </template>
      <!-- 样式配置 -->
      <template v-if="activeData.styleObj !== undefined">
        <div class="Fg-field-name">样式配置</div>
        <StyleConfig
          v-model="activeData.styleObj"
          :list="formConf?.cssList"
          :disabled="activeData.isLock"
        />
      </template>
      <!-- 事件配置 -->
      <template v-if="activeData.event !== undefined">
        <div class="Fg-field-name">事件配置</div>
        <EventConfig v-model="activeData.event" :list="formConf?.eventList" />
      </template>
      <!-- 图标弹框 -->
      <HuIconsDialog ref="IconsVisible" v-model="activeData[currentIconModel]" />
    </el-form>
  </div>
</template>

<script>
import HuIconsDialog from "../huComponents/HuIconsDialog.vue";
import HuOptions from "../huComponents/HuOptions.vue";
import LayoutTree from "../huComponents/LayoutTree.vue";
// import HuExcel from "../huComponents/HuExcel.vue";
import StyleConfig from "../configComponents/StyleConfig.vue";
import EventConfig from "../configComponents/EventConfig.vue";
import TableConfig from "../configComponents/TableConfig.vue";
import CodeDialog from "@/components/editor/CodeDialog";
import InputColor from "../huComponents/InputColor";
import DataConfig from "../configComponents/DataConfig";
import RegConfig from "../configComponents/RegConfig";
import { isNumberStr } from "../utils/index";
import {
  dateTimeFormat,
  dateTypeOptions,
  dateRangeTypeOptions,
  colorFormatOptions,
  justifyOptions,
  fileTypeOptions,
} from "../utils/attribute";
import { inputComponents, selectComponents } from "../utils/config";
import { deepClone } from "../utils";
import store from "@/store";
import { MessageBox } from "element-ui";

// 使changeRenderKey在目标组件改变时可用
const needRerenderList = ["richText"];
export default {
  components: {
    HuIconsDialog,
    // HuExcel,
    HuOptions,
    LayoutTree,
    StyleConfig,
    TableConfig,
    CodeDialog,
    EventConfig,
    InputColor,
    DataConfig,
    RegConfig,
  },
  props: {
    // 表单属性
    formConf: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      activeData: {},
      currentIconModel: null, // 选择的图标的参数名称
      colorFormatOptions,
      justifyOptions,
      fileTypeOptions,
    };
  },

  watch: {
    activeData: {
      immediate: true,
      deep: true,
      handler(newValue) {
        if (JSON.stringify(newValue) !== JSON.stringify(this.currentData)) {
          this.setCurrentData(newValue);
        }
      },
    },
    currentData: {
      immediate: true,
      deep: true,
      handler(newValue) {
        this.activeData = deepClone(newValue);
      },
    },
  },

  computed: {
    // 当前选中表单组件
    currentData() {
      return store.state.app.activeData;
    },
    tagList() {
      return [
        { label: "输入型组件", options: inputComponents },
        { label: "选择型组件", options: selectComponents },
      ];
    },
    dateOptions() {
      if (
        this.activeData.type !== undefined &&
        this.activeData.__config__.tag === "form-date-picker"
      ) {
        if (this.activeData["start-placeholder"] === undefined) {
          return dateTypeOptions;
        }
        return dateRangeTypeOptions;
      }
      return [];
    },
    activeTag() {
      return this.activeData.__config__.tag;
    },
    isShowMin() {
      return ["form-input-number", "form-slider"].indexOf(this.activeTag) > -1;
    },
    isShowMax() {
      return (
        ["form-input-number", "form-slider", "form-rate"].indexOf(
          this.activeTag
        ) > -1
      );
    },
    isShowStep() {
      return ["form-input-number", "form-slider"].indexOf(this.activeTag) > -1;
    },
  },
  methods: {
    // 锁定
    handleLock(item) {
      const message = item.isLock
        ? "解锁后改组件可以修改任何配置"
        : "锁定后该组件将无法再修改任何配置";
      MessageBox.confirm(
        message,
        `确定要${item.isLock ? "解锁" : "锁定"}该组件吗？`,
        {
          type: "warning",
        }
      ).then(() => {
        item.isLock = !item.isLock;
      });
    },
    setCurrentData(item) {
      if (Object.keys(item).length) store.commit("SET_ACTIVEDATA", item);
    },
    // 打开图标弹框
    openIconsDialog(model) {
      this.currentIconModel = model;
      this.$refs.IconsVisible.onOpen();
    },

    addSelectItem() {
      this.activeData.__slot__.options.push({
        label: "",
        value: "",
      });
    },

    setDefaultValue(val) {
      if (Array.isArray(val)) {
        return val.join(",");
      }
      if (typeof val === "boolean") {
        return `${val}`;
      }
      return val;
    },
    onDefaultValueInput(str) {
      if (Array.isArray(this.activeData.__config__.defaultValue)) {
        // 数组
        this.$set(
          this.activeData.__config__,
          "defaultValue",
          str.split(",").map((val) => (isNumberStr(val) ? +val : val))
        );
      } else if (["true", "false"].indexOf(str) > -1) {
        // 布尔
        this.$set(this.activeData.__config__, "defaultValue", JSON.parse(str));
      } else {
        // 字符串和数字
        this.$set(
          this.activeData.__config__,
          "defaultValue",
          isNumberStr(str) ? str + "" : str
        );
      }
    },
    onSwitchValueInput(val, name) {
      if (["true", "false"].indexOf(val) > -1) {
        this.$set(this.activeData, name, JSON.parse(val));
      } else {
        this.$set(this.activeData, name, isNumberStr(val) ? +val : val);
      }
    },
    setTimeValue(val, type) {
      const valueFormat = type === "week" ? dateTimeFormat.date : val;
      this.$set(this.activeData.__config__, "defaultValue", null);
      this.$set(this.activeData, "value-format", valueFormat);
      this.$set(this.activeData, "format", val);
    },
    spanChange(val) {
      this.formConf.span = val;
    },

    dateTypeChange(val) {
      this.setTimeValue(dateTimeFormat[val], val);
    },
    rangeChange(val) {
      this.$set(
        this.activeData.__config__,
        "defaultValue",
        val
          ? this.activeData.min + "," + this.activeData.max
          : this.activeData.min
      );
    },
    rateTextChange(val) {
      if (val) this.activeData["show-score"] = false;
    },
    rateScoreChange(val) {
      if (val) this.activeData["show-text"] = false;
    },
    colorFormatChange(val) {
      this.activeData.__config__.defaultValue = null;
      this.activeData["show-alpha"] = val.indexOf("a") > -1;
      this.activeData.__config__.renderKey = +new Date(); // 更新renderKey,重新渲染该组件
    },

    setIcon(val) {
      this.activeData[this.currentIconModel] = val;
    },
    tagChange(tagIcon) {
      let target = inputComponents.find(
        (item) => item.__config__.tagIcon === tagIcon
      );
      if (!target)
        target = selectComponents.find(
          (item) => item.__config__.tagIcon === tagIcon
        );
      // 存储当前控件的id和字段名
      const formId = this.activeData.__config__.formId;
      const __vModel__ = this.activeData.__vModel__;
      this.activeData = deepClone(target);
      // 将旧数据id和字段名赋给新数据
      this.activeData.__config__.formId = formId;
      this.activeData.__vModel__ = __vModel__;
    },
    changeRenderKey() {
      if (needRerenderList.includes(this.activeData.__config__.tag)) {
        this.activeData.__config__.renderKey = +new Date();
      }
    },
  },
};
</script>

<style lang="scss" >
@import "../styles/generator.scss";

.time-range {
  .el-date-editor {
    width: 227px;
  }
  ::v-deep .el-icon-time {
    display: none;
  }
}
.document-link {
  position: absolute;
  display: block;
  width: 26px;
  height: 26px;
  top: 0;
  left: 0;
  cursor: pointer;
  background: $themeColor;
  z-index: 1;
  border-radius: 0 0 6px 0;
  text-align: center;
  line-height: 26px;
  color: #fff;
  font-size: 18px;
}
.Fg-field-name {
  // height: 28px;
  // line-height: 28px;
  font-size: 15px;
  margin: 32px -16px;
  margin-bottom: 16px;
  padding: 10px 16px;
  color: $themeColor;
  background: $selectedColor;
  font-weight: bold;
  font-style: italic;
  &:first-child {
    margin-top: -16px;
  }
}
.Fg-field {
  .el-select {
    width: 100%;
  }
  .Fg-field--top {
    .el-form-item__label {
      float: none;
    }
    .el-form-item__content {
      margin-left: 0 !important;
    }
  }
}
.Fg-reg-item {
  padding: 12px 6px;
  background: #f8f8f8;
  position: relative;
  border-radius: 4px;
  .close-btn {
    position: absolute;
    right: -6px;
    top: -6px;
    display: block;
    width: 16px;
    height: 16px;
    line-height: 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    color: #fff;
    text-align: center;
    z-index: 1;
    cursor: pointer;
    font-size: 12px;
    &:hover {
      background: rgba(210, 23, 23, 0.5);
    }
  }
  & + .Fg-reg-item {
    margin-top: 18px;
  }
}
</style>
